package com.lovo.homework;

import java.util.Scanner;

public class User {
    private String username;
    private String pwd;
    private String confirm;
    private String email;
    private Scanner sc = new Scanner(System.in);

    public void valid(){

        while(true){
            System.out.println("请输入用户名：");
            username = sc.next();
            if(!username.matches("^\\w{6,20}$")){
                System.out.println("用户名格式不正确，请重新输入");
            }else{
                break;
            }
        }
        while(true){
            System.out.println("请输入密码：");
            pwd = sc.next();
            if(!pwd.matches("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{6,}$")){
                System.out.println("密码格式不正确，请重新输入");
            }else{
                break;
            }
        }
        while(true){
            System.out.println("请输入确认密码：");
            confirm = sc.next();
            if(!confirm.equals(pwd)){
                System.out.println("两次密码不一致");
            }else{
                break;
            }
        }
        while(true){
            System.out.println("请输入邮箱：");
            email = sc.next();
            if(!email.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$")){
                System.out.println("邮箱格式不正确，请重新输入");
            }else{
                break;
            }
        }
        System.out.println("注册成功，" + username + " " + pwd + " " + email);

    }

    public static void main(String[] args) {
        User user = new User();
        user.valid();
    }
}
